const path = getSystemContextPath();

// 滚动到指定位置
function smoothJump(route) {
    let h = $("html, body")
    h.stop();
    h.animate({scrollTop: $(route).offset().top}, "slow");
}

// js获取系统上下文路径
function getSystemContextPath(){
    // 获取当前页面的上下文路径
    return contextPath = window.location.pathname.split('/').slice(0, 2).join('/');
}

// 数字格式化
function formatNumberWithUnit(num) {
    const units = ['', 'K', 'M', 'G', 'T'];
    let index = 0;

    while (num >= 10000) {
        num /= 1000;
        index++;
    }

    const formattedNum = num % 1 === 0 ? num.toFixed(0) : num.toFixed(1);
    return formattedNum + units[index];
}

// 截断文本
function truncateText(element, maxLength, ellipsis) {
    const text = $(element).text();
    if (text.length > maxLength) {
        $(element).text(text.slice(0, maxLength) + ellipsis);
    }
}